package com.ft.f_springboot_route.controller;

import com.ft.f_springboot_route.bean.Shop;
import com.ft.f_springboot_route.service.ShopService;
import com.ft.f_springboot_route.service.impl.ShopServiceImpl;
import com.ft.f_springboot_route.utils.Pager;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/shop")
@Controller
public class ShopController {

    @Autowired
    private ShopService shopServiceImpl;

    @RequestMapping("/toShopList")
    public String toShopList(String shopName, String shopTel,String shopAdderss,Integer currentPage,Model model){

        String name=null;
        String tel=null;
        String addredss=null;
        if (shopName !=null && !shopName.equals(" ")){
            name=shopName;
            model.addAttribute("shopName",name);
        }
        if (shopTel !=null && !shopTel.equals(" ")){
            tel=shopTel;
            model.addAttribute("shopTel",tel);
        }
        if (shopAdderss !=null && !shopAdderss.equals(" ")){
            addredss=shopAdderss;
            model.addAttribute("shopAdderss",addredss);
        }
        System.out.println(name +"----");
        Pager<Shop> pager = shopServiceImpl.pager(currentPage, name, tel, addredss);
        model.addAttribute("pager",pager);



        return "shop/shoplist";
    }

    @RequestMapping("/toShopAdd")
    public String toShopAdd(){
        return "shop/addshop";
    }
    @RequestMapping("addShop")
    public String addShop(Shop shop){

        shopServiceImpl.AddShop(shop);
        return "redirect:/shop/toShopList";
    }

    @RequestMapping("/goShopxiu")
    public String toShopEdit(Integer shopId ,Model model){
        Shop shop = shopServiceImpl.SelectShopId(shopId);
        model.addAttribute("shop",shop);
        return "shop/setshop";
    }
    @RequestMapping("/editShop")
    public String editShop(Shop shop){
        shopServiceImpl.EditShop(shop);
        return "redirect:/shop/toShopList";
    }

    @RequestMapping("/delShop")
    public String delShop(Integer shopId){
        shopServiceImpl.DelShopById(shopId);
        return "redirect:/shop/toShopList";
    }
}
